package com.example.task;

import org.springframework.stereotype.Component;

import java.time.LocalTime;

@Component
public class timetask implements Runnable {

    private volatile boolean running = true;

    @Override
    public void run() {
        int count = 0;
        while (running && count < 60) {
            System.out.println(" 当前时间: " + LocalTime.now());
            try {
                Thread.sleep(1000); // 每秒一次
                count++;
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
        }
        System.out.println(" 倒计时60秒完成！");
    }

    public void stop() {
        this.running = false;
    }
}